package net.lico;

import org.apache.commons.lang.StringUtils;

import java.io.*;
import java.nio.charset.Charset;
import java.util.*;

public class CompareShouxin {
    public static void main(String[] args) {
//        Set<String> lineSet25 = getLineSet("C:\\Users\\lirun\\Desktop\\手心输入法双拼自定义短语_2019_01_25.txt");
//        Set<String> lineSet24 = getLineSet("D:\\键道6挂载\\键道6挂载手心\\dict.txt");
//        Set<String> lineSetYD = getLineSet("D:\\一道\\星空一道歌颂终结版\\rime\\dict-palminput.txt");
//        Set<String> lineSetJD = getLineSet("D:\\Program Files\\Rime_JD\\rime\\dict-palminput.txt");
        
//        Set<String> all = new HashSet<String>();
//        all.addAll(lineSetJD);
//        all.addAll(lineSet25);
//        List<String> newList = new ArrayList<String>();
//        
//        Iterator<String> iterator = all.iterator();
//        while (iterator.hasNext()){
//            String line = iterator.next().trim();
//            line = line.substring(line.lastIndexOf(",")+1);
//            if((line.length()==1 || line.length()==2)) {
//                if (/*lineSet24.contains(line) && */lineSetYD.contains(line)) {
//                    continue;
//                }
//                newList.add(line);
////                System.out.println(line);
//            }
//        }
//        Iterator<String> iterator1 = lineSetJD.iterator();
//        while (iterator1.hasNext()){
//            String next = iterator1.next();
//            String chineseStr = next.substring(next.lastIndexOf(",")+1);
//            if(newList.contains(chineseStr)){
//                System.out.println(next);
//            }
//        }

//        Set<String> lineSetYD_add = getLineSet("G:\\soft\\viewer&editor\\input\\一道\\星空一道歌颂终结版\\dict_adding.txt");
//        Set<String> lineSetYD_de = getLineSet("G:\\soft\\viewer&editor\\input\\一道\\星空一笔道(一道点儿词库)0412_sign\\dict-palminput.txt");
//        Set<String> lineSetYD_de = getLineSet("G:\\soft\\viewer&editor\\input\\一道\\星空一笔道0911\\dict-palminput.txt");
        Set<String> lineSetYD_add = getLineSet("G:\\soft\\viewer&editor\\input\\一道\\搜狗\\dict-0708-12.txt");
        Set<String> lineSetYD_de = getLineSet("G:\\soft\\viewer&editor\\input\\一道\\搜狗\\dict-0708-test.txt");
        Iterator<String> addIter = lineSetYD_add.iterator();
        List<String> notInList = new ArrayList<String>();
//        Iterator<String> deIter = lineSetYD_de.iterator();
        Map<String,String> map = new HashMap<String, String>();
        for (String s : lineSetYD_de) {
            String chineseStr = s.trim();
            chineseStr = chineseStr.substring(chineseStr.lastIndexOf(",")+1);//只跑一遍，缓存结果到map里面
            map.put(chineseStr,s);
        }
        while (addIter.hasNext()){
            String addStr = addIter.next();
            String s = map.get(addStr);
            if(s == null){
                notInList.add(addStr);
            } else{
                System.out.println(s);
            }
        }
        System.out.println("===================== 不存在的");
        for (String s : notInList) {
            System.out.println(s);
        }

    }
    public static Set<String> getLineSet(String path){
        Set<String> result =new HashSet<String>();
        BufferedReader bufferedReader = null;
        try {
            InputStreamReader isr = new InputStreamReader(new FileInputStream(path)/*, Charset.availableCharsets().get("UTF-16LE")*/);
            bufferedReader = new BufferedReader(isr);
            String line = null;
            while ((line = bufferedReader.readLine())!=null){
                if(StringUtils.isNotBlank(line)) {
                    result.add(line);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(bufferedReader!=null){
                try {
                    bufferedReader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return result;
    }
    
}
